<script>
import CardItems from '@/components/CardItems'
import { cardConfig, treeConfig } from './config/cardConfig'
import { popConfig } from './config/popConfig'
import { headerConfig } from './config/tableConfig'
import { selectConfig } from './config/selectConfig'
import TreeCard from '@/components/TreeCard/index.vue'

export default {
  name: 'sceneFloor',
  components: {
    TreeCard,
    CardItems
  },
  data() {
    return {
      isExpand: true,
      expandLeft: 200,
      nodeSelect: {}
    }
  },
  computed: {
    treeConfig() {
      return treeConfig['scene-floor'] || {}
    },
    /**
     * 卡片配置
     */
    cardConfig() {
      return cardConfig['scene-floor'] || {}
    },
    /**
     * 弹窗配置
     */
    popConfig() {
      return popConfig['scene-floor'] || {}
    },
    /**
     * 筛选配置
     */
    selectConfig() {
      return selectConfig['scene-floor'] || []
    },
    /**
     * 表头配置
     */
    headerConfig() {
      return headerConfig['scene-floor'] || []
    }
  },
  methods: {
    handleNodeClick(data) {
      if (data.type === 1) {
        this.nodeSelect = {sceneProjectId: data.id};
      } else if (data.type === 2) {
        this.nodeSelect = {sceneEdificeId: data.id};
      } else if (data.type === 3) {
        this.nodeSelect = {ids: [data.id]};
      } else if (data.type === 4) {
        this.nodeSelect = {sceneRoomId: data.id};
      }
      this.$nextTick(() => {
        this.$refs.tableCard?.getData()
      })
    }
  }
}
</script>

<template>
  <div class="scene-floor-box">
    <div class="TreeCard-box" :class="{'is-expand':!isExpand}" :style="{width: `${expandLeft}px`}">
      <TreeCard
        class="tree-card"
        :tree-config="treeConfig"
        @handleNodeClick="handleNodeClick"
      />
    </div>
    <div class="CardItems-box">
      <CardItems
        ref="tableCard"
        :outer-params="nodeSelect"
        :card-config="cardConfig"
        :pop-config="popConfig"
        :select-config="selectConfig"
        :header-config="headerConfig"
      />
    </div>
  </div>
</template>
<style lang="scss" scoped>
.scene-floor-box {
  display: flex;
  width: 100%;
  height: 100%;

  .CardItems-box {
    flex: 1;
  }
}
</style>
